package written.test;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/17  15:27
 * @Description:
 */
public class ThreeSixZero1 {
    static int[][] cost = new int[][]{{0,0},{100,120},{200,350},{360,200},{220,320}};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = 100;
        while(n-->0) solve(sc.nextLine());
    }
    public static void solve(String s){
        int n = s.length();
        int[][] dp = new int[n][n];
        for(int i = 0; i<n-1;i++){
            char ch1 = s.charAt(i), ch2 = s.charAt(i+1);
            if(ch1 != ch2){
                dp[i][i+1] = Math.min(
                        Math.min(cost[ch1-'0'][0], cost[ch1-'0'][1]),
                        Math.min(cost[ch2-'0'][0], cost[ch2-'0'][1]));
            }
        }
//        show(dp);
        for(int len = 3; len <= n; len++){
            for(int i = 0; i <= n-len; i++){
                int j = i + len -1;
                char ch1 = s.charAt(i), ch2 = s.charAt(j);
                //删除一边的代价
                dp[i][j] = Math.min(dp[i+1][j] + cost[ch1-'0'][1],
                        dp[i][j-1] + cost[ch2-'0'][1]);
                //删除两边
//                dp[i][j] = Math.min(dp[i][j], dp[i+1][j-1] + cost[ch1-'0'][1] + cost[ch2-'0'][1]);
                //插入一边
                dp[i][j] = Math.min(dp[i][j],
                        Math.min(dp[i+1][j] + cost[ch1-'0'][0],
                                dp[i][j-1] + cost[ch2-'0'][0])
                  );

                if(ch1 == ch2) {
                    dp[i][j] = Math.min(dp[i][j], dp[i+1][j-1]);
                }
            }
        }
//        show(dp);
        System.out.println(dp[0][n-1]);
    }
    public static void show(int[][] nums){
        System.out.println("===================");
        for(int[] a: nums){
            System.out.println(Arrays.toString(a));
        }
        System.out.println("===================");
    }
}
